package com.oauth.twitter.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.Widget;
import com.oauth.components.client.rpc.OAuthAsnyCallBack;
import com.oauth.twitter.client.beans.TwitterModel;
import com.oauth.twitter.client.rpc.TwitterRemoteServiceAsync;

public class MainPanel extends Composite {

	private static MainPanelUiBinder uiBinder = GWT.create(MainPanelUiBinder.class);

	interface MainPanelUiBinder extends UiBinder<Widget, MainPanel> {
	}

	/**
	 * Create a remote service proxy to talk to the server-side Greeting
	 * service.
	 */
	@UiField
	HomePanel homePanel;

	@UiField
	DeckPanel deckPanel;

	public MainPanel() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public void initMainPanel() {
		deckPanel.showWidget(0);
		TwitterRemoteServiceAsync.INSTANCE.getTweets(new OAuthAsnyCallBack<TwitterModel>() {

			public void onSuccess(TwitterModel result) {
				homePanel.setData(result);
				deckPanel.showWidget(1);

			}
		});
	}

	public void setVisible(boolean visible) {
		this.setVisible(visible);
		if (visible) {
			initMainPanel();
		}
	}
}